package be.dch.objectprops.formatter;

import java.lang.reflect.UndeclaredThrowableException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatter implements Formatter {

    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");

    @SuppressWarnings("rawtypes")
    
    public Class getFormatterClass() {
	return Date.class;
    }

    
    public Object parse(final String input) {
	Object result = null;
	if (input != null) {
	    try {
		result = DateFormatter.FORMAT.parse(input);
	    } catch (final ParseException ex) {
		throw new UndeclaredThrowableException(ex);
	    }
	}
	return result;
    }

    
    public String format(final Object input) {
	final Date d = (Date) input;
	return DateFormatter.FORMAT.format(d);
    }

    
    public void parse(final String input, Object result) {
	throw new UnsupportedOperationException("Method parse(String,Object) not supporeted.");
    }

}
